home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / cagdmesh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  3.8 KB  |  96 lines

  1. /******************************************************************************
  2. * CagdMesh.c - Extract surface control mesh/curve control polygon as polyline *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Aug. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * DESCRIPTION:                                                               M
  11. * Extracts the control polygon of a curve as a polyline.             M
  12. *                                                                            *
  13. * PARAMETERS:                                                                M
  14. *   Crv:        To extract a control polygon from.                           M
  15. *                                                                            *
  16. * RETURN VALUE:                                                              M
  17. *   CagdPolylineStruct *:  The control polygon of Crv.                       M
  18. *                                                                            *
  19. * KEYWORDS:                                                                  M
  20. *   CagdCrv2CtrlPoly, control polygon                                        M
  21. *****************************************************************************/
  22. CagdPolylineStruct *CagdCrv2CtrlPoly(CagdCrvStruct *Crv)
  23. {
  24.     int i,
  25.     Length = Crv -> Length + (Crv -> Periodic != FALSE);
  26.     CagdRType
  27.     **CrvP = Crv -> Points;
  28.     CagdPolylnStruct *NewPolyline;
  29.     CagdPolylineStruct *P;
  30.  
  31.     P = CagdPolylineNew(Length);
  32.     NewPolyline = P -> Polyline;
  33.  
  34.     for (i = 0; i < Length; i++) {
  35.     CagdCoerceToE3(NewPolyline -> Pt, CrvP, i % Crv -> Length,
  36.                Crv -> PType);
  37.     NewPolyline++;
  38.     }
  39.     return P;
  40. }
  41.  
  42. /*****************************************************************************
  43. * DESCRIPTION:                                                               M
  44. * Extracts the control mesh of a surface as a list of polylines.         M
  45. *                                                                            *
  46. * PARAMETERS:                                                                M
  47. *   Srf:        To extract a control mesh from.                             M
  48. *                                                                            *
  49. * RETURN VALUE:                                                              M
  50. *   CagdPolylineStruct *:  The control mesh of Srf.                          M
  51. *                                                                            *
  52. * KEYWORDS:                                                                  M
  53. *   CagdSrf2CtrlMesh, control mesh                                           M
  54. *****************************************************************************/
  55. CagdPolylineStruct *CagdSrf2CtrlMesh(CagdSrfStruct *Srf)
  56. {
  57.     int i, j,
  58.     ULength = Srf -> ULength + (Srf -> UPeriodic != FALSE),
  59.     VLength = Srf -> VLength + (Srf -> VPeriodic != FALSE);
  60.     CagdRType
  61.     **SrfP = Srf -> Points;
  62.     CagdPolylnStruct *NewPolyline;
  63.     CagdPolylineStruct *P,
  64.     *PList = NULL;
  65.  
  66.     for (j = 0; j < VLength; j++) {       /* Generate the rows of the mesh. */
  67.     P = CagdPolylineNew(ULength);
  68.     NewPolyline = P -> Polyline;
  69.  
  70.     for (i = 0; i < ULength; i++) {
  71.         CagdCoerceToE3(NewPolyline -> Pt, SrfP,
  72.                CAGD_MESH_UV(Srf, i % Srf -> ULength,
  73.                          j % Srf -> VLength),
  74.                Srf -> PType);
  75.             NewPolyline++;
  76.     }
  77.     LIST_PUSH(P, PList);
  78.     }
  79.  
  80.     for (i = 0; i < ULength; i++) {       /* Generate the cols of the mesh. */
  81.     P = CagdPolylineNew(VLength);
  82.     NewPolyline = P -> Polyline;
  83.  
  84.     for (j = 0; j < VLength; j++) {
  85.         CagdCoerceToE3(NewPolyline -> Pt, SrfP,
  86.                CAGD_MESH_UV(Srf, i % Srf -> ULength,
  87.                          j % Srf -> VLength),
  88.                Srf -> PType);
  89.             NewPolyline++;
  90.     }
  91.     LIST_PUSH(P, PList);
  92.     }
  93.  
  94.     return PList;
  95. }
  96.